//
//  SimpleMemoryCache.m
//  SimpleWebImage
//
//  Created by Jiang on 2019/8/26.
//  Copyright © 2019 SilverFruity. All rights reserved.
//

#import "SimpleMemoryCache.h"

@implementation SimpleMemoryCache

- (instancetype)init
{
    self = [super init];
    self.imageCaches = [NSCache new];
    return self;
}
- (nullable UIImage *)imageForKey:(nonnull NSString *)key {
    return [self.imageCaches objectForKey:key];
}

- (BOOL)saveImage:(UIImage *)image forKey:(NSString *)key{
    if (image) {
        [self.imageCaches setObject:image forKey:key];
        return YES;
    }else{
        return NO;
    }
}
- (void)removeImageForKey:(NSString *)key{
    [self.imageCaches removeObjectForKey:key];
}

@end
